package com.hu.bgp.client.widgets;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.hu.bgp.shared.ClientScore;

public class ScoreTable extends HeaderedFlexTable
{
	private int rows = 1;
	private int columns = 0;

	public ScoreTable()
	{
		super();
		clear();
		this.getElement().addClassName("bgptable");
	}

	public void addScoreRow(ClientScore score)
	{
		new ScoreRow(createRow(score));
	}

	public void clear()
	{
		super.clear();
		rows = 1;
		columns = 0;
		for (Label l : createHeader())
		{
			this.setHeaderElement(columns++, l.getElement());
		}
	}

	public Label[] createHeader()
	{
		return new Label[]
		{
			new Label("Id"), new Label("Score")
		};
	}

	public Widget[] createRow(ClientScore score)
	{
		return new Widget[]
		{
			new Label(score.getId()), new Label(score.getScore())
		};
	}

	protected class ScoreRow
	{
		public ScoreRow(Widget[] fields)
		{
			int rc = 0;
			for (Widget w : fields)
			{
				setWidget(rows, rc++, w);
			}
			rows++;
		}
	}
}
